/**
方法二：每次移除3000ms之前的请求记录。因为这些记录之后都不会再用到
*/

export var RecentCounter = function () {
  this.pings = []
}

/**
 * @param {number} t
 * @return {number}
 */
RecentCounter.prototype.ping = function (t) {
  this.pings.push(t)
  const target = t - 3000
  if (target <= 0) return this.pings.length
  let cur = this.pings[0]
  while (cur < target) {
    this.pings.shift()
    cur = this.pings[0]
  }
  return this.pings.length
}

/**
 * Your RecentCounter object will be instantiated and called as such:
 * var obj = new RecentCounter()
 * var param_1 = obj.ping(t)
 */
